// import COS from './cos-wx-sdk-v5.min.js';
// const COS = require('cos-wx-sdk-v5.min.js');

export function uploadFile(cosObject, file) {
	return new Promise(async (resolve, reject) => {
		let cos = new COS({
			SecretId: cosObject.Credentials.TmpSecretId,
			SecretKey: cosObject.Credentials.TmpSecretKey,
			XCosSecurityToken: cosObject.Credentials.Token,
			ExpiredTime: cosObject.ExpiredTime
		});
		cos.putObject({
			Bucket: cosObject.bucket,
			Region: cosObject.region,
			Key: file.split('http://')[1],
			FilePath: file,
			SliceSize: 1024 * 1024 * 5,
			onProgress: function(progressData) {

			}
		}, (err, data) => {
			if (err) {
				reject(err)
			} else {
				let path = data.Location
				resolve(path)
			}
		});
		return;
	})
}